/**
 * @author CT
 * @email 994599447@qq.com
 * @date 2017.8.16
 */

'use strict';

import React, { Component } from 'react';
import {
    StatusBar,
    InteractionManager,
    View,
} from 'react-native';
import { NavigationActions } from 'react-navigation'
import * as I18n from '../config/i18n'
import * as Storage from '../common/storage'
import SplashScreen from 'react-native-splash-screen'
import * as config from '../config/appConfig'
import Utils from '../common/utils'
import AppIntro from 'react-native-app-intro';


/**
 * 程序欢迎页
 */
export default class WelcomePage extends Component {
    constructor(props) {
        super(props);
    }


    //跳转至首页
    _intoHomePage = () => {
        const {navigator} = this.props;
        InteractionManager.runAfterInteractions(() => {
            //跳至首页
            //Reset方法会清除原来的路由记录，添加上新设置的路由信息
            const resetAction = NavigationActions.reset({
                index: 0,
                actions: [
                    NavigationActions.navigate({ routeName: 'HomePage'}),
                ]
            })
            this.props.navigation.dispatch(resetAction)
        });
    }

    componentWillUnmount() {
        //将是否是不是首次启动设置为tue
        Storage.save(config.StorageKey.IsNotFirstStartAPP,true);
    }

    _doneBtnHandle = () => {
        this._intoHomePage();
    }
    
    render() {
        //欢迎页数据
        const pageArray = [{
                title: I18n.t('welcome.page1_title'),
                description: I18n.t('welcome.page1_description'),
                img: 'http://demo.sc.chinaz.com/Files/pic/icons/6602/d11.png',
                imgStyle: {
                    height: 120,
                    width: 120,
                },
                backgroundColor: '#99CC00',
                fontColor: '#fff',
                level: 10,
            }, {
                title: I18n.t('welcome.page2_title'),
                description: I18n.t('welcome.page2_description'),
                img:'http://demo.sc.chinaz.com/Files/pic/icons/6602/d14.png',
                imgStyle: {
                    height: 120,
                    width: 120,
                },
                backgroundColor: '#4598dc',
                fontColor: '#fff',
                level: 10,
        }];
        return (
            <AppIntro
                    ref={(intro)=>{this.intro = intro}}
                    pageArray={pageArray}
                    showSkipButton={false}
                    onDoneBtnClick={this._doneBtnHandle}
                />
        );
    }
    
}